Do not allow decoding transactions with an unsupported version#871
Conversation
🦋 Changeset detectedLatest commit: 6e00621 The changes in this PR will be included in the next version bump. This PR includes changesets to release 41 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
BundleMonFiles updated (7)
Unchanged files (123)
Total files change +590B +0.16% Final result: ✅ View report in BundleMon website ➡️ |
| if (value > MAX_SUPPORTED_TRANSACTION_VERSION) { | ||
| throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, { | ||
| unsupportedVersion: value, | ||
| }); | ||
| } |
There was a problem hiding this comment.
I've also disallowed encoding a TransactionVersion > 0, but I haven't added other checks for encoding because I don't think there's risk of accidentally encoding the wrong versions from Kit APIs, and we have a Typescript type for valid versions.
I mostly did this because I don't think it makes sense to have different supported/unsupported versions in the encode and decode tests.
|
Documentation Preview: https://kit-docs-2vu8exd9a-anza-tech.vercel.app |
69c5e04 to
ab69e7c
Compare
| [SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_OUT_OF_RANGE]: | ||
| 'Transaction version must be in the range [0, 127]. `$actualVersion` given', | ||
| [SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED]: | ||
| 'This version of Kit does not support decoding transactions with version $unsupportedVersion. The current max supported version is 0.', |
There was a problem hiding this comment.
I like this better than what I wrote in the offchain messages PR. I'm going to use this instead.
| if ( | ||
| compiledTransactionMessage.version !== 'legacy' && | ||
| compiledTransactionMessage.version > MAX_SUPPORTED_TRANSACTION_VERSION | ||
| ) { | ||
| throw new SolanaError(SOLANA_ERROR__TRANSACTION__VERSION_NUMBER_NOT_SUPPORTED, { | ||
| actualVersion: compiledTransactionMessage.version, | ||
| }); | ||
| } | ||
|
|
There was a problem hiding this comment.
Does this need to be here? If we:
- Hardcode
0into theVersionedCompiledTransactionMessagetype. - Can't decode v1 transactions with the codec after this PR.
…then you should never be able to obtain one of these data structures, right?
There was a problem hiding this comment.
I think you're right, updated. The test I added for this is now a type error (version: 1) so I removed that test. But I think this is cleaner and it makes more sense to restrict the type there.
ab69e7c to
154a047
Compare
154a047 to
defcbe9
Compare
defcbe9 to
6e00621
Compare
|
Because there has been no activity on this PR for 14 days since it was merged, it has been automatically locked. Please open a new issue if it requires a follow up. |
Problem
Kit currently supports codecs for legacy transactions, and transactions with version 0. There's currently a SIMD for transactions with version 1, which drastically changes how transactions are encoded. Kit will currently decode transactions claiming to have transaction message 1, but this decoding will be nonsense when such transactions exist.
Summary of Changes
We now throw a SolanaError when we decode a transaction and receive a version number greater than 0.
A future version of Kit will be able to add support for v1 transactions, while continuing to throw for still unsupported versions.
Fixes #866